clear all;  addpath('auxiliar'); addpath('Simulated_Datasets');load SIMULATION_ERGODIC_DE
bg=10;
shoc=25;
figure
Dlim=KAPYT./q_big;
mY=meanY;
[imax,idend]=max(squeeze(bp_cc(bg,:,shoc)));
idstart=0;
for i=1:NB-1
if BGp_cc(bg,i,shoc)<BGp_cc(bg,i+1,shoc) && idstart==0
    idstart=i+1;
end
end
idend=idend-1;
% idstart = find(squeeze(BGp_cc(bg,:,shoc))>BGp_cc(bg,1,shoc));
  grey1  = [220 220 255]./255;
   grey2  = [170 170 255]./255;
    grey3  = [120 120 255]./255;
% BGP_cc is expected public debt conditional on repayment


%yyaxis left
area(bgrid(bg,1:idstart-1)/mY,cte_debtfactor*squeeze(BGp_cc(bg,1:idstart-1,shoc))/mY,'basevalue',0,'FaceColor',grey1); hold on;
area(bgrid(bg,idstart-1:idend+1)/mY,cte_debtfactor*squeeze(BGp_cc(bg,idstart-1:idend+1,shoc))/mY,'basevalue',0,'FaceColor',grey2); hold on;
area(bgrid(bg,idend+1:end)/mY,cte_debtfactor*squeeze(BGp_cc(bg,idend+1:end,shoc))/mY,'basevalue',0,'FaceColor',grey3); hold on;

plot(bgrid(bg,:)/mY,cte_debtfactor*squeeze(BGp_cc(bg,:,shoc))/mY,'Linewidth',2,'Color','b','LineStyle','-','Marker','none'); hold on;
plot(bgrid(bg,:)/mY,squeeze(bp_cc(bg,:,shoc))/mY,'Linewidth',2,'Color','r','LineStyle','-','Marker','none'); hold on;
plot(bgrid(bg,:)/mY,bgrid(bg,:)/mY,'Linewidth',2,'Color','k','LineStyle','-','Marker','none');hold on;legend boxoff;
ylim([bgrid(bg,1)/mY, .5]);
ylabel('End of period debt','Interpreter','Latex'); legend boxoff;
%yyaxis right
%plot(bgrid(bg,:)/mY,squeeze(Qgov_cc(bg,:,shoc))/mY,'Linewidth',2,'Color','r','LineStyle',':'); hold on;
%ylabel('Price of public debt'); legend boxoff;



xlabel('Current private debt ($B$)','Interpreter','Latex')

Hlegend=legend('Low current debt ','Medium current debt','High current debt','End of period public debt ($L''$)','End of period private debt ($b''$)','45 degree','Location','northwest'); set(Hlegend,'Interpreter','Latex')
hold off;xlim([bgrid(bg,1)/mY, .5]);
exportfig(gcf,'Plots\Fig7_Pubdebt.eps','color','cmyk','resolution',1600)

BGgrid(bg,1)*cte_debtfactor/mY
